//
//  VideoTableViewCell.m
//  VideoPic
//
//  Created by GH on 16/3/21.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "VideoTableViewCell.h"
#import "ModelForVideo.h"
#import <YYWebImage.h>


@interface VideoTableViewCell ()
@property (nonatomic ,retain)UILabel *labelOfUserName;
@property (nonatomic ,retain)UILabel *labelOftype;
@property (nonatomic ,retain)UILabel *labelContect;
@property (nonatomic ,retain)UIImageView *imageOfHead;
@property (nonatomic ,retain)UILabel * labelOfCap;

@end

@implementation VideoTableViewCell


- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createLabel];
        [self createImage];
    }
    return self;
}

- (void)createLabel {

    self.labelOfUserName = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfUserName];
    
    self.labelOftype = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOftype];
    
    self.labelContect = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelContect];
    self.labelContect.numberOfLines = 0;
    
    self.labelOfCap = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfCap];
    self.labelOfCap.font = [UIFont systemFontOfSize:12];
    
    
}

- (void)createImage {

    self.imageOfHead = [[UIImageView alloc] init];
    [self.contentView addSubview:self.imageOfHead];

}

-(CGFloat)heightForLabel:(NSString *)text{
    
    CGRect rect = [text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 40, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:17]} context:nil];
    
    
    return rect.size.height;
}



- (void)passWithModel:(ModelForVideo *)model {

    self.labelOfUserName.text = model.name;
    self.imageOfHead.yy_imageURL = [NSURL URLWithString:model.avatar_url];
    self.labelContect.text = model.text;
    self.labelContect.numberOfLines = 0;
    self.labelOfCap.text = model.category_name;

}



- (void)layoutSubviews {
    [super layoutSubviews];
    
    //头像
    self.imageOfHead.frame = CGRectMake(20, 20, SCREEN_WIDTH / 10, SCREEN_WIDTH / 10);
    self.imageOfHead.layer.masksToBounds = YES;
    self.imageOfHead.layer.cornerRadius = SCREEN_WIDTH / 20;
    
    //用户名
    self.labelOfUserName.frame = CGRectMake(30 + SCREEN_WIDTH / 10, 20 + SCREEN_WIDTH/ 20 - 13, SCREEN_WIDTH/2, 25);
    self.labelOfUserName.font = [UIFont systemFontOfSize:13];
    
    //title
    self.labelContect.frame = CGRectMake(20, 20 + SCREEN_WIDTH /10 +15, SCREEN_WIDTH  - 40, [self heightForLabel:self.labelContect.text]);
    
    CGFloat titleBom = [self heightForLabel:self.labelContect.text] + 35 + SCREEN_WIDTH / 10;
    //cap
    if (self.labelContect == nil) {
        self.labelOfCap.frame = CGRectMake(20, titleBom + 15 - 20, 70, 20);

    }else {
        self.labelOfCap.frame = CGRectMake(20, titleBom + 15, 70, 20);
    }
    self.labelOfCap.textAlignment = 1;
    self.labelOfCap.layer.borderWidth = 1;
    self.labelOfCap.layer.borderColor = [UIColor blackColor].CGColor;
    self.labelOfCap.layer.masksToBounds = YES;
    self.labelOfCap.layer.cornerRadius = 10;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
